package org.lex.utils.text;

import java.util.ArrayList;

public abstract class Tokenizers {
	// public static final SingleCharDelimiterTokenizer LineSplitter;
	// public static final SingleCharDelimiterTokenizer BlankSpaceSplitter;
	public static final Tokenizers DotSplitter = get('.');
	public static final Tokenizers SemicolonSplitter = get(';');
	public static final Tokenizers CommaSplitter = get(',');
	public static final Tokenizers PipeSplitter = get('|');
	public static final Tokenizers BackslashSplitter = get('/');

	public static Tokenizers get(final char sep) {
		return new Tokenizers() {
			SingleCharDelimiterTokenizer t = new SingleCharDelimiterTokenizer(null, sep, false);

			@Override
			public String[] split(String src) {
				t.reset(src);
				ArrayList<String> list = new ArrayList<String>();
				while (t.hasNext())
					list.add(t.next());
				return list.toArray(new String[list.size()]);
			}
		};
	}

	public abstract String[] split(String src);
}
